package tech.aistar.day14;

import tech.aistar.day07.interfaces.demo03.B;
import tech.aistar.day10.Book;

/**
 * 本类用来演示: 类的运行时类型
 *
 * @author: success
 * @date: 2021/3/25 9:42 上午
 */
public class ClassDemo {
    public static void main(String[] args) {
        //获取class实例 - 运行时类型
        Class<?> c1 = Book.class;
        System.out.println(c1);//class tech.aistar.day10.Book
        //对象.getClass();
        Book b1 = new Book(1,"1001","西游记",100.0d);
        Book b2 = new Book(2,"1002","西游记2",100.0d);
        Class<?> c2 = b1.getClass();
        System.out.println(c2);//class tech.aistar.day10.Book

        //一个类无论被实例化多少次,它在JVM中的Class实例永远只有1个
        System.out.println(c1 == c2);//true
        System.out.println(b2.getClass() == c2);//true

        try {
            //类的权限定名 - 推荐使用的.
            Class<?> c3 = Class.forName("tech.aistar.day10.Book");
            System.out.println(c3);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        Class<?> c5 = int.class;
        System.out.println(c5);//int

    }
}
